<?php defined('SYSPATH') or die('No direct script access.');

//префикс таблиц, лучше не трогать
define('TABLE_PREFIX','amz_');

require SYSPATH.'classes/kohana/core'.EXT;// Load the core Kohana class
if (is_file(APPPATH.'classes/kohana'.EXT))
    require APPPATH.'classes/kohana'.EXT;// Application extends the core
else
    require SYSPATH.'classes/kohana'.EXT;// Load empty core extension

date_default_timezone_set('Europe/Kiev');
setlocale(LC_ALL, 'en_US.utf-8');
spl_autoload_register(array('Kohana', 'auto_load'));//Enable the Kohana auto-loader.
ini_set('unserialize_callback_func', 'spl_autoload_call');//Enable the Kohana auto-loader for unserialization.

// -- Configuration and initialization -----------------------------------------
I18n::lang('en-us');//Set the default language

//Cookies tmp path, must be writtable!
define('COOKIES', APPPATH . 'cache/cookie');

/**
 * Set Kohana::$environment if a 'KOHANA_ENV' environment variable has been supplied.
 *
 * Note: If you supply an invalid environment name, a PHP warning will be thrown
 * saying "Couldn't find constant Kohana::<INVALID_ENV_NAME>"
 */
if (isset($_SERVER['KOHANA_ENV']))
{
    Kohana::$environment = constant('Kohana::'.strtoupper($_SERVER['KOHANA_ENV']));
}

/**
 * Initialize Kohana, setting the default options.
 *
 * The following options are available:
 *
 * - string   base_url    path, and optionally domain, of your application   NULL
 * - string   index_file  name of your index file, usually "index.php"       index.php
 * - string   charset     internal character set used for input and output   utf-8
 * - string   cache_dir   set the internal cache directory                   APPPATH/cache
 * - integer  cache_life  lifetime, in seconds, of items cached              60
 * - boolean  errors      enable or disable error handling                   TRUE
 * - boolean  profile     enable or disable internal profiling               TRUE
 * - boolean  caching     enable or disable internal caching                 FALSE
 * - boolean  expose      set the X-Powered-By header                        FALSE
 */
Kohana::init(array(
    'base_url'   => '/',
    'index_file' => '',
    'cache_dir' => APPPATH . '/cache',
    'errors' => TRUE,
));

/**
 * Attach the file write to logging. Multiple writers are supported.
 */
Kohana::$log->attach(new Log_File(APPPATH.'logs'));

/**
 * Attach a file reader to config. Multiple readers are supported.
 */
Kohana::$config->attach(new Config_File);

/**
 * Enable modules. Modules are referenced by a relative or absolute path.
 */
Kohana::modules(array(
	 'auth'       => MODPATH.'auth',       // Basic authentication
	// 'cache'      => MODPATH.'cache',      // Caching with multiple backends
	// 'codebench'  => MODPATH.'codebench',  // Benchmarking tool
	 'database'   => MODPATH.'database',   // Database access
	// 'image'      => MODPATH.'image',      // Image manipulation
	 'orm'        => MODPATH.'orm',        // Object Relationship Mapping
	 'unittest'   => MODPATH.'unittest',   // Unit testing
	// 'userguide'  => MODPATH.'userguide',  // User guide and API documentation
    'email'       => MODPATH.'email', // E-mail
 	));

/**
 * Set the routes. Each route must have a minimum of a name, a URI and a set of
 * defaults for the URI.
 */
//Product item
Route::set('curr', 'shop/product/<asin>', array('asin' => '[A-Z0-9]{3,}'))
        ->defaults(array(
            'controller' => 'shop',
            'action' => 'product',
            'param' => 'asin'
        ));
Route::set('cart', 'shop/cart/<asin>', array('asin' => '[A-Z0-9]{3,}'))
        ->defaults(array(
            'controller' => 'shop',
            'action' => 'cart',
            'param' => 'asin'
        ));
Route::set('category', 'shop/cat/<cat>', array('cat' => '[A-Za-z0-9 -&]{3,}'))
        ->defaults(array(
            'controller' => 'shop',
            'action' => 'cat',
            'param' => 'cat'
        ));
Route::set('wish', 'shop/wishlist/<asin>', array('asin' => '[A-Z0-9]{3,}'))
        ->defaults(array(
            'controller' => 'shop',
            'action' => 'wishlist',
            'param' => 'asin'
        ));
Route::set('default', '(<controller>(/<action>(/<id>)))')
        ->defaults(array(
            'controller' => 'shop',
            'action' => 'index',
        ));

Cookie::$salt = 'aMz';

if(!isset($_SERVER['HTTP_HOST']))
    $_SERVER['HTTP_HOST'] = 'amz.org.ua';